package workquene;

import com.rabbitmq.client.*;
import org.junit.Test;
import utils.ConnectionUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author xj
 * @create 2021/8/12 12:08
 */
public class Customer02 {

    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = ConnectionUtils.getConnection("localhost", 5672, "/xj", "xj", "123");
        Channel channel = connection.createChannel();

        channel.queueDeclare("work", true, false, false, null);

        channel.basicConsume("work", true, new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者02 = " + new String(body));
            }
        });
    }

}
